package com.Controller.Admin;

import com.Common.CodeMsg;
import com.Common.ResultModel;
import com.Model.Admin.Role;
import com.Model.Admin.UserInfo;
import com.Params.UserInfoParams;
import com.Service.Admin.RoleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

@Controller
public class RoleInfoController {

    @Autowired
    RoleService roleService;

    @RequestMapping(value = "admin/roleInfoIndex")
    public String roleIndex() {
        return "admin/RoleMnger";
    }

    @RequestMapping(value = "/admin/allRoleInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel roleInfo(UserInfoParams userParams) throws IOException {


        PageInfo<Role> lst = roleService.getRoleInfosByQuery(userParams);
        ResultModel resultModel;
        if (lst == null) {
            resultModel = new ResultModel(CodeMsg.nonData.getIndex(), CodeMsg.nonData.getName(), null);
        } else {
            resultModel = new ResultModel(CodeMsg.success.getIndex(), CodeMsg.success.getName(), lst.getList());
        }

        return resultModel;
    }

}
